package com.lagou.common.pojo.constant;

import lombok.Data;

import javax.persistence.AttributeConverter;

/**
 * @author cyt
 * @date 2020/11/24
 */
public enum OrderStatus {

    UNPAY(1,"未支付"),
    PAIED(2,"已支付"),
    INVALID(3,"已失效"),
    DELETED(4,"已删除");


    Integer code;

    String desc;

    OrderStatus(Integer code, String desc){
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode(){
        return this.code;
    }


    public static class Converter implements AttributeConverter<OrderStatus, Integer> {

        @Override
        public Integer convertToDatabaseColumn(OrderStatus orderStatus) {
            return orderStatus.code;
        }

        @Override
        public OrderStatus convertToEntityAttribute(Integer integer) {
            OrderStatus[] values = OrderStatus.values();

            for(OrderStatus status : values){
                if(status.code.equals(integer)){
                    return status;
                }
            }

            throw new RuntimeException("convert error!!");
        }
    }



}
